
const TOKEN_KEY = 'userToken';
const USER_MOBILE = 'showMobile';
const USER_INFO = 'userInfo';
const USER_AVATAR = 'userAvatar';
const User_Organization = 'userOrganization';

const isLogin = () => {
  return !!localStorage.getItem(TOKEN_KEY);
};

const getToken = () => {
  return localStorage.getItem(TOKEN_KEY);
};

const setToken = (token: string) => {
  localStorage.setItem(TOKEN_KEY, token);
};

const getUserOrganization = ()=>{
  return JSON.parse(localStorage.getItem(User_Organization) || '{}');
}

const setUserAvatar = (avatar: string)=>{
  localStorage.setItem(USER_AVATAR, avatar);
}

const setUserInfo = (userInfo: any)=>{
  localStorage.setItem(USER_INFO, JSON.stringify(userInfo || '{}'));
}

const getUserInfo = () =>{
  return JSON.parse(localStorage.getItem(USER_INFO) || '{}');
}

const clearUserInfo = ()=>{
  localStorage.removeItem(USER_INFO);
}

const setUserMobileList = (list : any) => {
  localStorage.setItem(USER_MOBILE, JSON.stringify(list));
}

const getUserMobileList = () => {
  return JSON.parse(localStorage.getItem(USER_MOBILE) || '[]')
}

const clearUserMobileList = () => {
  localStorage.removeItem(USER_MOBILE);
}


const getUserAvatar = ()=>{
  return localStorage.getItem(USER_AVATAR) || '';
}

const setUserOrganization = (data: any)=>{
  localStorage.setItem(User_Organization, data);
}

const clearUserOrganization = () => {
  localStorage.removeItem(User_Organization);
}

const clearUserAvatar = () => {
  localStorage.removeItem(USER_AVATAR);
}

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY);
  localStorage.removeItem(USER_MOBILE);
  localStorage.removeItem(USER_INFO);
  localStorage.removeItem(User_Organization);
};


export { 
  isLogin, 
  getToken, 
  setToken, 
  clearToken,
  clearUserAvatar,
  setUserAvatar,
  getUserAvatar,
  setUserInfo,
  getUserInfo,
  clearUserInfo,
  setUserMobileList,
  getUserMobileList,
  clearUserMobileList,
  setUserOrganization,
  clearUserOrganization,
  getUserOrganization
};
